<?php 
session_start();
if(isset($_POST['login'])){
    //将表单输入字符转成 字符串
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    //验证账号的正确性
    if(($username=='') || ($password=='')){
        //重定向 跳转制定网页
        header('refresh:3;url=login.html');
        echo "该用户名或密码不能为空，3秒后跳转到登录页面";
        exit;
    }
    else if (($username!='username') || ($password!='password')){
        header('refresh:3;url=login.html');
        echo "该用户名或密码错误，3秒后跳转到登录页面";
    }
    else if (($username=='username') || ($password=='password')){
        $_SESSION['username']=$username;
        $_SESSION['islogin']=1;
        //7天内自动登录
        if ($_POST['remember']=='yes'){
            setcookie("username",$username,time+7*24*60*60);
            setcookie("code",md5($username.md5($password)),time()+7*24*60*60);
        }
        else{
            setcookie("username",'',time()-1);
            setcookie("code",'',time()-1);
        }
        header("location:index.php");
    }
    
}
?>

<?php
// //保存用户信息（临时）
// $userData = array(
//     array("username"=>"admin","password"=>"123456"),
//     array("username"=>"gaozhen","password"=>"666666")
//     //......
// );


// if (isset($_POST['login'])){
//     session_start();
//     $username = $_POST['username'];
//     $password = $_POST['password'];
//     foreach ($userData as $value){
//         if ($value['username'] == $username && $value['password'] == $password){
            
//             $_SESSION['user'] = $username;
//             header("Location:showinfo.php");//重定向，跳转到首页
//             exit();
//         }
//     }
//     exit("登录失败！") ;
// }

?>